#!/bin/bash

# Generate a file descriptor for the dataset
hadoop fs -rm -r traindata/
hadoop fs -rm -r testdata/
hadoop fs -mkdir traindata
hadoop fs -mkdir testdata
hadoop fs -put movies_refine_train traindata/
hadoop fs -put movies_refine_test testdata/
hadoop jar /usr/lib/mahout/mahout-core-0.9-cdh5.2.0-job.jar org.apache.mahout.classifier.df.tools.Describe -p traindata/movies_refine_train -f traindata/movies_refine_train.info -d 2 I 2 C I 28 C N I L I 5 N

# Run the example
hadoop fs -rm -r nsl-forest
hadoop jar /usr/lib/mahout/mahout-examples-0.9-cdh5.2.0-job.jar org.apache.mahout.classifier.df.mapreduce.BuildForest -Dmapred.max.split.size=1574231 -d traindata/movies_refine_train -ds traindata/movies_refine_train.info -sl 6 -p -t 100 -o nsl-forest

# Using the Decision Forest to Classify new data
hadoop fs -rm -r predictions
hadoop jar /usr/lib/mahout/mahout-examples-0.9-cdh5.2.0-job.jar org.apache.mahout.classifier.df.mapreduce.TestForest -i testdata/movies_refine_test -ds traindata/movies_refine_train.info -m nsl-forest -a -mr -o predictions

# Show Forest
#hadoop jar /usr/lib/mahout/mahout-examples-0.9-cdh5.2.0-job.jar org.apache.mahout.classifier.df.tools.ForestVisualizer -ds traindata/movies_refine_train.info -m nsl-forest
